#include "slwp.h"
#include"config.h"
SLWP::SLWP()
{
    //初始化加载飞机图片
    m_slwp.load(SLW_PATH);
    //初始化飞机坐标
    m_X=0;
    m_Y=(GAME_HEIGHT-m_slwp.height())*0.5;
    //初始化矩形边框
    m_Rect.setWidth(m_slwp.width());
    m_Rect.setHeight(m_slwp.height());
    m_Rect.moveTo(m_X,m_Y);
}
void SLWP::shoot()
{
    //累加时间
    m_recorder++;
    //未达到间隔就不发射
    if(m_recorder<BULLET_INTERVAL)
    {
        return;
    }
    //达到间隔
    m_recorder=0;
    for(int i=0;i<BULLET_NUM;i++)
    {
        //如果空闲 发射
        if(m_bullets[i].m_Free)
        {
            m_bullets[i].m_Free=false;
            m_bullets[i].m_X=m_X+m_Rect.width()*0.5+30;
            m_bullets[i].m_Y=m_Y+50;
            break;
        }
    }
}

void SLWP::setPosition(int x, int y)
{
    m_X=x;
    m_Y=y;
    m_Rect.moveTo(m_X,m_Y);
}
